package com.jml.代理模式.五期.service.cglib.调试代理类;


/**
 * 类似FastClass
 */
public class FastClass {
    /**
     * 方法的索引
     * @param index
     * @param obj
     * @param args
     * @return
     */
    public static Object invoke(int index, Object obj, Object[] args) {
        MemberServiceImpl memberService= (MemberServiceImpl) obj;
        switch (index){
            case 1:
                return memberService.addMember(String.valueOf(args[0]));
        }
        return null;
    }

    /**
     * 签名 方法名称+参数类型
     *
     * @param sign
     * @return
     */
    public static int getIndex(String sign) {
        switch (sign.hashCode()) {
            case 2019430652:
                return 1;
            case 56807949:
                return 2;
        }
        return -1;
    }

    public static void main(String[] args) {
        String name = "addUser(String)";
        System.out.println(name.hashCode());
        Object result = invoke(getIndex(name), new MemberServiceImpl(), new Object[]{10});
        System.out.println(result);
    }
}
